let htmlTemplate = require('./index.art');
let _util = require('util/util.js');
let _index = require('service/indexService.js');
require('./index.css');


let UploadModal = function () {
    let _this = this;

    //关闭弹窗
    $(document).on('click', '.close-btn , .jsCloseModal', function (e) {
        $('.upload-wrapper').hide();
    });

    //上传excel zip
    $(document).on('click', '.uploadExcel', function (e) {
        let fileList = document.getElementById('uploadExcelZip-btn').files,
            formData = new FormData(),
            $uploadErrDom = $('.upload-error');

        $uploadErrDom.hide();

        if (!fileList.length) {
            let $uploadErrDom = $('.upload-error');
            $uploadErrDom.text('没有选择文件！').show();
            return;
        }

        formData.append('excelZip[]', fileList);

        _index.uploadExcelZip({
            formData: formData,
        })
    });

    $(document).on('change', '#uploadExcelZip-btn', function (e) {
        let fileListLenth = this.files,
            $uploadErrDom = $('.upload-error');
        if (!fileListLenth) {
            $uploadErrDom.show();
        } else {
            $uploadErrDom.hide();
        }
    })

}

UploadModal.prototype.render = function (option) {
    if (!(option.container instanceof window.jQuery)) {
        return
    }

    let renderedHtml = _util.renderHtml(__dirname + htmlTemplate, {});
    option.container.html(renderedHtml);
}

module.exports = UploadModal;